package com.lzd.pgyuploader.utils

import java.text.SimpleDateFormat

class TextUtil {
    public static def ANSI_RESET = "\u001B[0m"
    public static def ANSI_BLACK = "\u001B[30m"
    public static def ANSI_RED = "\u001B[31m"
    public static def ANSI_GREEN = "\u001B[32m"
    public static def ANSI_YELLOW = "\u001B[33m"
    public static def ANSI_BLUE = "\u001B[34m"
    public static def ANSI_PURPLE = "\u001B[35m"
    public static def ANSI_CYAN = "\u001B[36m"
    public static def ANSI_WHITE = "\u001B[37m"

    enum Color {
        reset,
        red,
        yellow,
        green,
    }

    /**
     * 为文本设置颜色
     */
    static String getColorString(String str, Color color) {
        def target
        switch (color) {
            case Color.red:
                target = ANSI_RED
                break
            case Color.yellow:
                target = ANSI_YELLOW
                break
            case Color.green:
                target = ANSI_GREEN
                break
            default:
                target = ANSI_RESET
        }
        " ${target} ${str} ${ANSI_RESET} "
    }

    static String getNowTime() {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy年MM月dd日 hh:mm:ss")
        return sdf.format(Calendar.getInstance().getTime())
    }
}
